package com.android.clinic.app.ui.personal;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;

import com.android.clinic.app.ClinicApplication;
import com.android.clinic.app.R;
import com.android.clinic.app.base.BaseActivity;
import com.android.clinic.app.http.HttpClient;
import com.android.clinic.app.http.base.BaseObserver;
import com.android.clinic.app.http.utils.RxObservableUtils;

/**
 * Created by cheng on 2018/2/8.
 * 绑定VIP
 */
public class BindVipActivity extends BaseActivity {

    private EditText etNumber, etPassword;
    private String mobile;

    @Override
    protected int getLayoutResId() {
        return R.layout.activity_bind_vip;
    }

    @Override
    protected void initView(@Nullable Bundle savedInstanceState) {
        setTitleBarTitle("绑定VIP");
        setTitleBarLeftResource(R.drawable.icon_back);

        TextView tvMobile = (TextView) findViewById(R.id.tv_mobile);
        etNumber = (EditText) findViewById(R.id.et_number);
        etPassword = (EditText) findViewById(R.id.et_password);

        mobile = ClinicApplication.getUserInfo().getMobile();
        tvMobile.setText(mobile);

    }

    @Override
    protected void widgetClick(View v) {
        super.widgetClick(v);
        if (v.getId() == R.id.btn_confirm) {
            if (etNumber.getText().toString().trim().length() == 0) {
                showToast("请输入序列号!");
                return;
            }
            if (etPassword.getText().toString().trim().length() == 0) {
                showToast("请输入密码!");
                return;
            }
            HttpClient.getHttpService().bindVip(ClinicApplication.getUserInfo().getId(),
                    mobile,
                    etNumber.getText().toString().trim(),
                    etPassword.getText().toString().trim())
                    .compose(this.bindToLifecycle())
                    .compose(RxObservableUtils.applySchedulers(loading, ""))
                    .subscribe(new BaseObserver<String>() {
                        @Override
                        public void onSuccess(String s) {
                            showToast("已成功绑定VIP!");
                            finish();
                        }

                        @Override
                        public void onFailure(String message) {
                            showToast(message);
                        }
                    });
        }
    }
}
